/*
 * @Author: captern
 * @@Gitee: https://gitee.com/captern
 * @@websit: http://www.captern.cn/
 * @Date: 2020-06-22 09:25:49
 * @LastModifiedBy: captern
 * @LastEditTime: 2020-08-14 14:11:41
 * @Description:
 */
import React from "react"
import storage from "good-storage"
import PropTypes from "prop-types"
import { observer, inject } from "mobx-react"
import { getQuery, removeQuery } from "../../utils/common"
import ApiModel from "../../api/apiModel/apiModel"
import userAuthFun from "../../api/userAuth"
import CheckMethod from "./checkMethod/checkMethod"
import CheckTheme from "./checkTheme/checkTheme"
import MethodMsg from "./methodMsg/methodMsg"
import UploadMsg from "./uploadMsg/uploadMsg"
import UploadSuccess from "./uploadSuccess/uploadSuccess"

@inject("UserStore")
@observer
class Upload extends React.Component {
  static contextTypes = {
    router: PropTypes.object.isRequired,
  }
  constructor(props) {
    super(props)
    this.state = {}
  }
  async componentWillMount() {
    if (
      !this.props.UserStore.repeatUploadFlag &&
      !this.props.UserStore.watchRule
    ) {
      let userMsg = await ApiModel.getUserMsg()
      if (userMsg && userMsg.code === 0) {
        userAuthFun.checkUserStatus(userMsg)
      } else {
        storage.set("token", "")
        let newUrl = removeQuery("code", window.location.href)
        window.location.href = newUrl
      }
      // this.props.UserStore.changeValus('repeatUploadFlag', false)
    }
  }
  componentDidUpdate() {
    window.scrollTo(0, 0)
  }
  componentDidMount() {
    this.props.UserStore.setWatchRule(false)
  }
  componentWillUnmount() {
    console.log("页面， 卸载了")
  }

  render() {
    let { status } = this.props.UserStore
    return (
      <div>
        {status === "method" ? <CheckMethod /> : null}
        {status === "theme" ? <CheckTheme /> : null}
        {status === "methodMsg" ? <MethodMsg /> : null}
        {status === "uploadMsg" ? <UploadMsg /> : null}
        {status === "uploadSuccess" ? <UploadSuccess /> : null}
      </div>
    )
  }
}

export default Upload
